perm filename VMTST.PAL[11,HE] blob sn#540643 filedate 1980-10-13 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00010 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	Program to test out communication with the Vision Module via the DR11-C
C00005 00003	Mini test loop
C00007 00004	Interrupt routines
C00008 00005	Sending routines
C00012 00006	Receiving routines
C00015 00007	Reset & bad requests
C00016 00008	VT05 I/O routines
C00018 00009	Various Vision Module Messages
C00020 00010	Data & Constants
C00023 ENDMK
C⊗;
;Program to test out communication with the Vision Module via the DR11-C

.INSRT STUFF.PAL[11,ARG]

; COMMANDS are:
	TRANS=	040000		; TRANSFER DATA COMMAND
	ERESET=	140000		; RESET
	ERESAK=	160000		; RESET ACKNOWLEDGE

; STATUS word values are:
;	OK=	0		; DONE WITH A CLR
	ERBUF0=	101000		; NO BUFFERS AVAILABLE FOR INPUT MESSAGE
	ERBUFS=	102000		; NEXT BUFFER IS TOO SMALL
	ERCHKS=	103000		; CHECKSUM ERROR

;DR11-C definitions

DRCSR  = 763770		;Control and Status register
DROBUF = 763772		;Output Buffer register
DRIBUF = 763774		;Input Buffer register

DRIVEC = 340		;Request A & B interrupt vectors

.=DRIVEC
DRINTA			;Req A interrupt handler
240			;Level 5
DRINTB			;Req B interrupt handler
240			;Level 5


.=1000

START:	RESET
	MOV #START,SP		;Set up the stack
	MOV #BEGMES,R1		;Tell world who we are
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	CLR %PS			;Priority level 0

;Initialize the DR11-C link

	MOV #DRINTA,DRIVEC	;Set up interrupt vectors
	MOV #DRINTB,DRIVEC+4
	CLR STATE		;We're not doing anything yet
	MOV #140,DRCSR		;Enable interrupts

;See if anyone's home

	MOV #6,STATE		;Send a RESET & see if it gets acknowledged
	MOV #ERESET,DROBUF
	INC DRCSR		;Int A in VM

	MOV #100,R1		;Now wait a while for the reset acknowledge
1$:	CLR R0
2$:	TST STATE
	BEQ 3$			;STATE will be set to 0 when we get the resak
	SOB R0,2$
	SOB R1,1$

	MOV #TIMMES,R1		;Time out
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	BR START		;Try again

3$:	BIS #2,DRCSR		;Set CSR 1 for "B" response (may not be needed)

;Mini test loop

TLOOP:	MOV #RDYMES,R1		;Ready to send a message over
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	CLR CKSUM
	MOV MESS,R0		;R0 ← address of message to send
	MOV (R0)+,R1		;R1 ← Message length in bytes
	MOV R1,R2
	INC R2			;In case odd number of bytes
	ASR R2			;Convert bytes → word count
	MOV R2,SCNT		;Set up word count
	MOV R0,SPTR		;Set up pointer at message
	MOV #RBUF,RPTR		;Reset receive message pointer
	BIS #TRANS,R1		;R1 ← Send command bits + byte count
	MOV R1,DROBUF		;Get ready to send it
	BIC #3,DRCSR		;Clear CSR 0 & 1 bits
	MOV #1,STATE
	CLR SDONE
	CLR RDONE
	MOV #TSNMES,R1		;Say we're trying to send it now
	JSR PC,OUTSTR
	INC DRCSR		;"A" Request for command

1$:	TST SDONE		;Wait for it to have been sent
	BEQ 1$
	MOV #TRCMES,R1		;Now we want to receive the VM's reply
	JSR PC,OUTSTR
2$:	TST RDONE		;Wait for it to have been received
	BEQ 2$
	MOV #DONMES,R1		;Done - now we can look at the VM's reply
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BR TLOOP		;Ready to do it all again

;Interrupt routines

DRINTA:	MOV R0,-(SP)
	MOV #ADISP,R0		;Use A dispatch table
	BR DRINT
DRINTB:	MOV R0,-(SP)
	MOV #BDISP,R0		;Use B dispatch table
DRINT:	MOV R1,-(SP)
	MOV R2,-(SP)
	MOV R3,-(SP)
	BIC #3,DRCSR		;Clear interrupt requests
	MOV DRIBUF,R3		;R3 ← Anything sent over to us
	ADD STATE,R0
	ADD STATE,R0		;Get offset into dispatch table
	JMP @0(R0)			;Go do it

INTRB:	BIS #2,DRCSR		;Signal with a B request
INTRET:	MOV (SP)+,R3
	MOV (SP)+,R2
	MOV (SP)+,R1
	MOV (SP)+,R0
	RTI

;Sending routines

; In case he's not ready to start receiving when we want to send

A1:	BIC #777,R3		;Clear all non-status bits
	CLR STATE		;So we can receive
	CMP #ERBUF0,R3		;No buffers error?
	BNE 2$
	MOV #NBFMES,R1
1$:	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	BR INTRB
2$:	CMP #ERBUFS,R3		;Buffer too small?
	BNE 3$
	MOV #SBFMES,R1
	BR 1$
3$:	CMP #ERESET,R3		;External Reset?
	BNE 4$
	MOV #ERESAK,DROBUF	;Send a reset acknowledge
	INC DRCSR		;Int A
	MOV #RESMES,R1
	BR 1$
4$:	MOV #ERRMES,R1
	BR 1$

;It's okay with him to send - ship it over

B1:	INC STATE
	MOV #SNDMES,R1		;Say we're sending it now
	JSR PC,OUTSTR
B2:	DEC SCNT		;More to send?
	BPL 1$			; yes - do it
	MOV CKSUM,DROBUF	; no - go send cksum
	INC STATE		; Update state
	BR INTRB		; B Req & return
1$:	MOV @SPTR,R0		;Fetch next word to send
	XOR R0,CKSUM		;Update check sum
	MOV R0,DROBUF		;Move it to output buffer
	ADD #2,SPTR		;Bump pointer
	BR INTRB		;B Req & return

;Done sending - see if he received it okay

A3:	TST R3			;Check status
	BMI 1$			; Error skip ahead
	CLR STATE		;Done here
	INC SDONE
	BR INTRB		;B Req & return so VM can continue

1$:	CMP #ERESET,R3		;Remote Reset?
	BNE 2$			; no
	MOV #ERESAK,DROBUF	;Send a reset acknowledge
	INC DRCSR		;Int A
	MOV #RESMES,R1
	BR 3$
2$:	MOV #CHKMES,R1		;Must be a checksum error
3$:	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	CLR CKSUM
	MOV MESS,R0		;R0 ← address of message to send
	MOV (R0)+,R1		;R1 ← Message length in bytes
	MOV R1,R2
	INC R2			;In case odd number of bytes
	ASR R2			;Convert bytes → word count
	MOV R2,SCNT		;Set up word count
	MOV R0,SPTR		;Set up pointer at message
	BIS #TRANS,R1		;R1 ← Send command bits + byte count
	MOV R1,DROBUF		;Get ready to send it
	BIC #3,DRCSR		;Clear CSR 0 & 1 bits
	MOV #1,STATE
	CLR SDONE
	CLR RDONE
	MOV #RSDMES,R1		;Say we're sending it now
	JSR PC,OUTSTR
	INC DRCSR		;"A" Request for command
	BR INTRET		;Return from interrupt

;Receiving routines

;Ready to start receiving

A0:	TST R3			;See if transfer request
	BGT 3$			; yes - skip ahead & do it
	BIC #17777,R3		;Clear all except command bits
	BNE 1$
	JMP INTRB		;Null status - just ignore
1$:	CMP #ERESET,R3		;Make sure it was a reset
	BNE 2$
	MOV #ERESAK,DROBUF	;Send a reset acknowledge
	INC DRCSR		;Int A & return
	JMP INTRET
2$:	MOV #ERRMES,R1		;What's going on?
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	MOV #ERESET,DROBUF	;Try to reset things
	INC DRCSR
	MOV #6,STATE		;Wait for reset acknowledgement
	JMP INTRET

3$:	BIC #TRANS,R3		;Clear command bits
	MOV R3,@RPTR		;Store byte count
	ADD #2,RPTR
	INC R3			;In case odd number of bytes
	ASR R3			;Convert bytes to words
	MOV R3,RCNT		;Store it
	CLR CKSUM
	MOV #4,STATE		;Receive data
	MOV #RCVMES,R1		;Say that we're receiving
	JSR PC,OUTSTR
	JMP INTRB		;B response & return

;Store the message away now

B4:	DEC RCNT		;More to message?
	BMI 1$			; no - go get checksum
	MOV R3,@RPTR		;Store data away
	ADD #2,RPTR
	XOR R3,CKSUM		;Accumulate checksum
	JMP INTRB		;B response & return

1$:	CMP R3,CKSUM		;Checksum okay
	BNE 2$			; No
	INC STATE		; Yes - send ok status & wait til ok to proceed
	CLR DROBUF
	INC DRCSR		;A response & return
	JMP INTRET

2$:	MOV #CHKMES,R1		;Checksum error
	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	MOV #RRCMES,R1		;Request retransmission
	JSR PC,OUTSTR
	CLR STATE
	MOV #ERCHKS,DROBUF
	INC DRCSR		;Req A
	JMP INTRET

;Done receiving

B5:	INC RDONE		;Let everyone know that we're done
	CLR STATE
	JMP INTRET

;Reset & bad requests


;Waiting for Reset Acknowledgement

A6:	BIC #17777,R3		;Strip to command bits
	CMP #ERESET,R3		;Check for VM reseting also
	BNE 2$			; no
	MOV #ERESAK,DROBUF	; yes - acknowledge his
	INC DRCSR		;Req A & return
1$:	JMP INTRET
2$:	CMP #ERESAK,R3		;Is VM acknowledging us?
	BNE 1$			; no - ignore it
	CLR STATE		; yes - ok
	JMP INTRB		;B response & return

;Ignore Req B's

B0:	JMP INTRET

;Bad Requests

ABAD:	MOV #ABDMES,R1		;Complain
	BR BAD1
BBAD:	MOV #BBDMES,R1		;Complain
BAD1:	JSR PC,OUTSTR
	MOV #CRLF,R1
	JSR PC,OUTSTR
	BPT
	JMP INTRET

;VT05 I/O routines

OUTSTR:	MOVB (R1)+,R0		;Get next char
	BEQ 1$			;If done - quit
	JSR PC,OUTCHR		;Print it
	BR OUTSTR
1$:	JSR PC,OUTCHR		;Print a couple nulls
	JSR PC,OUTCHR
;	JMP OUTCHR

OUTCHR:	TST OUTSW		;Who does it go to?
	BEQ 2$
1$:	TSTB KBOS		;VT05 ready?
	BPL 1$			;Loop til it is
	MOVB R0,KBOR		;Print the char
	RTS PC
2$:	TSTB OREG		;Console ready?
	BNE 2$			;Wait til it is
	MOVB R0,OREG		;Output char
	RTS PC

INCHR:	TST OUTSW		;Where does it come from?
	BEQ 1$
	TSTB KBIS		;Anything typed on VT05?
	BPL 2$			; No
	MOVB KBIR,R0		; Read the char
	RTS PC
1$:	TSTB IREG		;Anything from the 10?
	BEQ 2$			; No
	MOVB IREG,R0		; Fetch the char
	CLRB IREG
	RTS PC
2$:	CLR R0			;No input
	RTS PC

;Various Vision Module Messages


INIVIS:	.WORD 4,0,0	;Initialize communiations with Vision Module
RESTRT: .WORD 4,1,8.	;Soft Restart
PIC:	.WORD 2,2	;Take a picture
REPIC:	.WORD 2,3	;Reprocess the picture
GETFET:	.WORD 6,4,1,8.,0,0,0,0
BLINK:	.WORD 6,5,1,-1	;Blink blob
DLBLOB:	.WORD 4,6,1	;Delete blob
CALIB:	.WORD 4,7,1	;Calibrate
REMEM:	.WORD 12.,8.,7	;Create a new prototype (#=7)
	.ASCIZ /FOO/	;Named FOO
	.BLKW 10
RECOG:	.WORD 4,10,1	;Recognize blob
WHERE:	.WORD 8.,11.,1,9.,0	;Where are they all
SREAD:	.WORD 11.,13.	;Read switch value
	.ASCIZ /TRAINING/
	.BLKW 10
SWRITE:	.WORD 19.,14.,-1	;Set switch (off)
	.ASCIZ /KEEP-ALL-BLOBS/
	.BLKW 10
VREAD:	.WORD 24.,15.		;Read variable value
	.ASCIZ /IMAGE-PROCESSING-TIME/
	.BLKW 10
VWRITE:	.WORD 23.,16.		;Write variable value
	.FLT2 1.75
	.ASCIZ /CALIBRATION-SIZE/
	.BLKW 10
ERASE:	.WORD 4,24.,0		;Erase graphics overlay
CLEARW:	.WORD 12.,25.,0,0,100,20,0	;Clear an area
DRAW:	.WORD 12.,26.,0,0,20,100,-1	;Draw a vector
TEXT:	.WORD 13.,27.,0,0		;Display text
	.ASCIZ /Hello?/
	.BLKW 10

;Data & Constants

STATE:	0		;What we're doing:
			;  0 = nothing
			;  1 = waiting for ok to start sending
			;  2 = sending data & cksum
			;  3 = waiting for message received ok
			;  4 = receiving data & cksum
			;  5 = waiting for ok to continue
			;  6 = reset in progress

ADISP:	.WORD A0,A1,ABAD,A3,ABAD,ABAD,A6	;Req A dispatch table
BDISP:	.WORD B0,B1,B2,BBAD,B4,B5,BBAD	;Req B dispatch table

SBUF:	.BLKW 100	;Message to send
RBUF:	.BLKW 100	;Where we'll store the message

MESS:	SBUF		;Start of message to be sent
SPTR:	SBUF		;What to send next
SCNT:	0		;How much left to send
RPTR:	RBUF		;Where to store next word
RCNT:	0		;How much left to receive
CKSUM:	0

SDONE: 	.WORD 0		;Set when message has been sent
RDONE: 	.WORD 0		;Set when reply has been received

BEGMES:	.ASCII /πVision Module Communication Test Program/
CRLF:	.BYTE 12,15,0
RDYMES:	.ASCIZ /πReady to send./
TSNMES:	.ASCIZ /πTrying to Send . . ./
SNDMES:	.ASCIZ /πSending . . . /
TRCMES:	.ASCIZ /πReady to Receive . . ./
RCVMES: .ASCIZ /πReceiving . . ./
DONMES: .ASCIZ /πDone./

;Error messages

TIMMES:	.ASCIZ /πTime out on reset acknowledge./
RESMES:	.ASCIZ /πExternal reset./
NBFMES:	.ASCIZ /πNo available buffers in VM./
SBFMES:	.ASCIZ /πToo small buffer in VM./
ERRMES:	.ASCIZ /πUnknown error./
RSDMES:	.ASCIZ /πRe-Sending . . ./
RRCMES:	.ASCIZ /πRequesting retransmission . . ./
CHKMES:	.ASCIZ /πChecksum error./
ABDMES:	.ASCIZ /πUnexpected A Request./
BBDMES:	.ASCIZ /πUnexpected A Request./

.END START